#ifndef CALCULATION_SERVER_H
#define CALCULATION_SERVER_H

#include <exception>
#include "matrix.h"
#include "shared_ptr.h"
#include "job.h"
#include "list.h"



class CalculationServer {
	List<mtm::shared_ptr<Job> > jobList;
	int counter;

public:
	typedef enum {
		SOLVE_EQUATION_SYSTEM, SIMILARITY, POLYNOMIAL
	} JobType;

	class CalculationServerException: public std::exception {
	};
	class OperationFailed: public CalculationServerException {
	};
	class JobNotFound: public CalculationServerException {
	};
	class InvalidPriority: public CalculationServerException {
	};

	CalculationServer();

	/* Adds a new job to the server's jobs.
	 Returns the new job's ID. */
	int addJob(JobType type, int priority, const Matrix& A, const Matrix& B);

	/* Removes the job with id = jobindex from the server's job. */
	void removeJob(int jobIndex);

	/* Changes the priority of the job with id = jobindex to newPriority */
	void changePriority(int jobIndex, int newPriority);

	/* executes the next job in queue. Returns the matrix calculated by the job. */
	Matrix execute();

	/* Returns the index of the next job to be performed. */
	int nextJob();

	/* Returns the total number of jobs in the queue. */
	int totalJobs();
};

#endif
